package com.huidu.bitrade.ext;

import org.apache.commons.lang3.StringUtils;
import org.springframework.session.web.http.HeaderHttpSessionIdResolver;

import javax.servlet.http.HttpServletRequest;
import java.util.Collections;
import java.util.List;

/**
 * 获取分布式session
 */
public class SmartSessionIdResolver extends HeaderHttpSessionIdResolver {
    public SmartSessionIdResolver(String headerName) {
        super(headerName);
    }


    private String tokenName = "x-auth-token";

    @Override
    public List<String> resolveSessionIds(HttpServletRequest request) {
        String headerValue = request.getHeader(tokenName);
        if (StringUtils.isBlank(headerValue)) {
            headerValue = request.getParameter(tokenName);
        }
        return (headerValue != null) ? Collections.singletonList(headerValue) : Collections.emptyList();
    }

}
